package com.messi.mall.seckill.scheduled;

import org.springframework.util.StringUtils;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class Test {
    public static void main(String[] args) {
        Test t = new Test();
        List<String> list1 = Arrays.asList("1","2","3");
        List<String> list2 = Arrays.asList("1","3","2");
        System.out.println(t.check(list1,list2));
    }
    private boolean check(List<String> collect, List<String> range) {
        if (isNull(collect) && isNull(range)) {
            return true;
        }
        List<String> listNull = isNull(collect) ? range : collect;
        List<String> listCheck = isNull(collect) ? collect : range;
        Map<String, Integer> totalMap = listNull.stream().collect(
                Collectors.toMap(x -> x,
                        x -> 0));
        if (isNull(listCheck)) {
            return false;
        }
        for (String s : listCheck) {
            if (StringUtils.isEmpty(totalMap.get(s))) {
                return false;
            } else {
                totalMap.put(s, 1);
            }
        }
        for (String s : listNull) {
            if (totalMap.get(s) == 0) {
                return false;
            }
        }
        return true;
    }
    private boolean isNull(List list) {
        return list == null || list.size() == 0;
    }
}
